﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static Kernel.Connection.GetPIDsConnectionInfo;

namespace CJFirewall.View
{
    /// <summary>
    /// ShowThis.xaml 的交互逻辑
    /// </summary>
    public partial class ShowThis : Window
    {
        private ConnectionInfo more;
        public ShowThis(ConnectionInfo more)
        {
            this.more = more;
            InitializeComponent();
            try {
                Tip.Text = $"进程PID:{more.PID}\n进程名称:{more.PIDName}\n运行时间:{more.ThisProcess.StartTime}";
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message,"警告");
                Tip.Text = $"进程PID:{more.PID}\n进程名称:{more.PIDName}\n";
            }
        }

        private void Close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Kill_Click(object sender, RoutedEventArgs e)
        {
            if (more.ThisProcess == null)
                return;
            try
            {
                more.ThisProcess.Kill();
            }
            catch(Exception ex) { MessageBox.Show(ex.Message, "操作失败"); }
        }

        private void Location_Click(object sender, RoutedEventArgs e)
        {
            Process nowpro = more.ThisProcess;
            string FileName = null ;
            try
            {  FileName = nowpro.MainModule.FileName; }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "操作失败"); 
            }
            finally
            {
                if(FileName!=null)
                    Process.Start("Explorer", "/select," + FileName);
            }
        }

        private void UnNetwork_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
